"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("path"));
const cp = tslib_1.__importStar(require("child_process"));
const utils_1 = require("./helper/utils");
exports.default = () => {
    let WORKER;
    if (process.env.NODE_ENV === 'development') {
        WORKER = cp.fork(path.join(__dirname, './workflow/index.ts'), [], { execArgv: ["-r", "ts-node/register"] });
    }
    else {
        WORKER = cp.fork(path.join(__dirname, './workflow/index.js'));
    }
    WORKER.on('error', async (err) => await utils_1.logError('fork', 'error', err));
    WORKER.on('message', async ({ message, type, repoName, tag }) => {
        if (process.env.NODE_ENV === 'test') {
            !type && await utils_1.logError(repoName, tag, message);
        }
        else {
            await (type ? utils_1.logInfo : utils_1.logError)(repoName, tag, message);
        }
    });
    WORKER.on('disconnect', console.error);
    return WORKER;
};
